define(['moment'], function (moment) {
    return ['$rootScope', '$scope', '$filter', '$stateParams', 'config', 'MMWService', '$compile', '$timeout', '$window',
        function ($rootScope, $scope, $filter, $stateParams, config, $MMWService, $compile, $timeout, $window) {
            $scope.init = function(){
                $scope.queryMode = 2;
                $scope.clickQueryMode($scope.queryMode);
            };

            $scope.back = function(){
                $scope.$root.hideMenu();
                $scope.$root.changeProgram('home', true);
            };
            
            $scope.clickQueryMode = function(query_mode){
                $scope.queryMode = query_mode;
                section_process_data_get({
                    model:0,
                    query_model:$scope.queryMode
                }, function(data){
                    $scope.item_list = data;
                    if($scope.item_list && $scope.item_list.length > 0)
                        $scope.clickProcessItem($scope.item_list[0]);
                });
            }

            $scope.clickProcessItem = function(item){
                $scope.now_process = item;
                section_process_data_get({
                    model:1,
                    query_model:$scope.queryMode,
                    section_process_no:$scope.now_process.section_process_no
                }, function(data){
                    $scope.op_flow_list = data.section_no_detail;
                    if($scope.op_flow_list && $scope.op_flow_list.length > 0)
                        $scope.clickFlowItem($scope.op_flow_list[0]);
                });
            }

            $scope.clickFlowItem = function(item){
                $scope.now_flow_op = item;
                section_process_data_get({
                    model:2,
                    query_model:$scope.queryMode,
                    section_process_no:$scope.now_process.section_process_no,
                    section_no:$scope.now_flow_op.section_no
                }, function(data){
                    $scope.item_collections = [
                        {
                            name:$filter('translate')('C14.wip_wastes'),
                            item_list:data.wip_detail
                        },
                        {
                            name:$filter('translate')('C14.delay_wastes'),
                            item_list:data.wait_detail
                        },
                        {
                            name:$filter('translate')('C14.defective_wastes'),
                            item_list:data.defect_detail
                        },
                        {
                            name:$filter('translate')('C14.overproduction'),
                            item_list:data.exceed_detail
                        }
                    ];
                });
            }

            function section_process_data_get(content, callback){
                $MMWService.sendToServer({
                    uri : 'ServicesSTD.Module_LEAN.section_process_data_get',
                    content : content,
                    success : function(data){
                        callback(data);
                        console.log(data);
                    }
                });
            }
        }
];});
